package com.lin.lazybone.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lin.lazybone.R;
import com.lin.lazybone.entity.Message;
import com.lin.lazybone.utils.L;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by mr.lin on 2017/11/23.
 */

public class MesListAdapter extends BaseAdapter
{
    private List<Message> mList;
    private Context mContext;
    private LayoutInflater layoutInflater;

    public MesListAdapter(Context mContext, List<Message> mList)
    {
        this.mContext = mContext;
        this.mList = mList;
        this.layoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public int getCount()
    {
        return mList.size();
    }

    @Override
    public Object getItem(int position)
    {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.meslist_item, null);
            viewHolder.meslist_touxiang = (CircleImageView) convertView.findViewById(R.id.meslist_touxiang);
            viewHolder.meslist_name = (TextView) convertView.findViewById(R.id.meslist_name);
            viewHolder.meslist_message = (TextView) convertView.findViewById(R.id.meslist_message);
            viewHolder.meslist_time = (TextView) convertView.findViewById(R.id.meslist_time);
            viewHolder.meslist_deltype = (ImageView) convertView.findViewById(R.id.meslist_deltype);
            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Message message = mList.get(position);
        viewHolder.meslist_touxiang.setImageResource(message.getTouxiang());
        viewHolder.meslist_name.setText(message.getYourname());
        viewHolder.meslist_time.setText(message.getTime());
        viewHolder.meslist_deltype.setImageResource(message.getDelImageId());
        viewHolder.meslist_message.setText(message.getRecentMes());
        return convertView;
    }

    class ViewHolder
    {
        private CircleImageView meslist_touxiang;
        private TextView meslist_name;
        private TextView meslist_message;
        private TextView meslist_time;
        private ImageView meslist_deltype;
    }

}
